package com.lemner.www.hongyu.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lemner.www.hongyu.Bean.FinishedrepairBean;
import com.lemner.www.hongyu.Bean.FinishorderBean;
import com.lemner.www.hongyu.R;
import com.lemner.www.hongyu.Service.Service;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class FinishrepairActivity extends AppCompatActivity {
  private EditText et_remark;
    private ImageView iv_uppic1;
    private Button btn_comfirm1;
    private Retrofit retrofit;
    private Service service;
    private static String BASEURL="http://www.hongyudasha.com/propertysystem/";
    private int worker_id,order_id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_finishrepair);
        worker_id=getIntent().getIntExtra("worker_id",1);
        order_id=getIntent().getIntExtra("order_id",1);
        InitView();

    }

    private void InitView() {
        et_remark=(EditText)findViewById(R.id.et_remark);
        iv_uppic1=(ImageView)findViewById(R.id.iv_uppic1);
        btn_comfirm1=(Button)findViewById(R.id.btn_confirm1);
        iv_uppic1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //多图片上传服务器逻辑
            }
        });
        btn_comfirm1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(TextUtils.isEmpty(et_remark.getText().toString())){
                    Toast.makeText(FinishrepairActivity.this,"备注不能为空",Toast.LENGTH_SHORT).show();
                }
                else{
                    getDate();

                }
            }
        });

    }
//提交维修结果
    public void getDate(){
       final String remark= et_remark.getText().toString();
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service=retrofit.create(Service.class);
        Call<FinishedrepairBean>call=service.commit(order_id,worker_id,remark,null);
        call.enqueue(new Callback<FinishedrepairBean>() {
            @Override
            public void onResponse(Call<FinishedrepairBean> call, Response<FinishedrepairBean> response) {
                if(response.body().getData().getSuccess()==0){
                    Toast.makeText(FinishrepairActivity.this,"提交成功",Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(FinishrepairActivity.this, DingdanActivity.class);
                    intent.putExtra("frxx",true);
                    startActivity(intent);
                }
            }

            @Override
            public void onFailure(Call<FinishedrepairBean> call, Throwable t) {
                Log.e("error",t.getMessage());
            }
        });
    }




}
